import { routes } from 'src/entry';
import { IRoutesModel } from './model';
import * as R from 'ramda';

class RouteManager{
  private routes: IRoutesModel = routes

  public registerRoute(route:any){
    // check一下
    this.routes.push(route)
  }
  public registerFilter () {
    return
  }
  public getRoutes(){
    return this.routes
  }
  // registerFilter
  public getAllRoutes() {
    this.setRoutesHref()
    return R.flatten(this.routes.map(route => route.children))
  }

  private setRoutesHref(){
    this.routes.forEach(route => {
      if (route.children) {
        route.children.forEach(child => {
          child.href = route.path + child.path
        })
      }
    })
  }
// public getPathByComponentName(name:string) {
//     // if (!name || this.routes.name == name) {
//     //     return this.route.path;
//     // }
//     return this.routes.find(x => x.name === name).path;
//   }
}

const routeManager = new RouteManager()

export default  routeManager